package com.helei.springcloud.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;


import java.util.concurrent.TimeUnit;

@Service
public class PaymentService {

    public String paymentInfo_ok(Integer id){
        return "线程池: "+Thread.currentThread().getName()+"id: "+id;
    }
    @HystrixCommand(fallbackMethod = "paymentInfo_TimeOutHeadler",commandProperties = {
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value = "3000")//线程超时
    })//fallbackMethod兜底方法
    public String paymentInfo_TimeOut(Integer id){
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "线程池: "+Thread.currentThread().getName()+"id: "+id;
    }

    public String paymentInfo_TimeOutHeadler(Integer id){

        return "网络不加";
    }
}
